<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'missionAssignment-form',
	'type' => 'horizontal',
	'enableClientValidation'=>true,
	'htmlOptions' => array('enableClientValidation'=>true), 
)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

		<?php echo $form->dropDownListRow($model, 'volunteer_id',CHtml::listData(
		Volunteer::model()->findAll(), 'id', 'volunteer'), array('prompt'=>'Select Volunteer..' )); ?>
	
		<?php echo $form->dropDownListRow($model, 'mission_area_id',CHtml::listData(
		MissionArea::model()->findAll(), 'id', 'mission_name'), array('prompt'=>'Select Mission..' )); ?>

		<?php echo $form->dropDownListRow($model,'assignment_length',array('prompt'=>'Select mission length..','6 mos'=>'6 months','1 yr'=>'1 year'))?>
			
		<?php echo $form->datepickerRow($model,'assignment_start_date',array('prepend' => '<i class="icon-calendar"></i>','options'=> array('format'=>'yyyy/mm/dd'))); ?>

		<?php echo $form->datepickerRow($model,'assignment_end_date',array('prepend' => '<i class="icon-calendar"></i>','options'=> array('format'=>'yyyy/mm/dd'))); ?>

		<?php echo $form->dropDownListRow($model,'assignment_status', $model->getStatus(), array('prompt'=>'select status..' ) ); ?>

		<?php echo $form->textFieldRow($model,'total_months_rendered'); ?>

	<div class="row">
		 <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit','type'=>'info','label'=>'create','icon'=>'ok-circle white')); ?>
		 <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'label'=>'cancel','icon'=>'remove-circle')); ?>
    </div>

<?php $this->endWidget(); ?>
<script type="text/javascript">
	$(document).ready(function(){
		var numbervalue = 0;
		var range ="";
		$('#MissionAssignment_assignment_length').change(function(){
			var selected = $(this).val().split(' ');
			numbervalue = selected[0];
			range = selected[1];
			console.log(numbervalue);
		});

		$('#MissionAssignment_assignment_start_date').change(function(){
			var selected = new Date($(this).val());
			var selectedMonth = selected.getMonth()+1;
			var selectedYear = selected.getFullYear();
			var selectedDate = selected.getDate();
			if(range=='mos')
				selectedMonth = selectedMonth+ +numbervalue;
			else
				selectedYear = selectedYear+ +numbervalue
			var endDate = selectedYear+'/'+ pad(selectedMonth,2)+'/'+ pad(selectedDate,2);
			$('#MissionAssignment_assignment_end_date').val(endDate);
		});

		function pad (str, max) {
		  str = str.toString();
		  return str.length < max ? pad("0" + str, max) : str;
		}
	});
</script>